package com.mapull.example.section1;

/**
 * StringReplace 字符串替换
 *
 * @author mapull
 * @date 2021-09-06
 * @since 1.0
 **/
public class StringReplace {

    public static void main(String[] args) {
        String originalString = "Whatever is worthwhile doing is worthwhile doing well";
        String newString = originalString.replaceAll("\\s", "-");

        System.out.println(originalString);
        System.out.println(newString);
    }

    public static void main7(String[] args) {
        String originalString = "Whatever is worthwhile doing is worthwhile doing well";
        String newString = originalString.replaceAll("worthwhile", "worth");

        System.out.println(originalString);
        System.out.println(newString);
    }

    public static void main6(String[] args) {
        String originalString = "Whatever is worthwhile doing is worthwhile doing well";
        String newString = originalString.replaceFirst("worth.*", "ok");

        System.out.println(originalString);
        System.out.println(newString);
    }

    public static void main5(String[] args) {
        String originalString = "Whatever is worthwhile doing is worthwhile doing well";
        String newString = originalString.replaceFirst("worthwhile", "worth");

        System.out.println(originalString);
        System.out.println(newString);
    }

    public static void main4(String[] args) {
        String originalString = "Whatever is worthwhile doing is worthwhile doing well";
        String newString = originalString.replace("worthwhile", null);
    }

    public static void main3(String[] args) {
        String originalString = "Whatever is worthwhile doing is worthwhile doing well";
        String newString = originalString.replace("worthwhile", "worth");

        System.out.println(originalString);
        System.out.println(newString);
    }

    public static void main2(String[] args) {
        String originalString = "枯藤，老树，昏鸦";
        String newString = originalString.replace('，', ',');

        System.out.println(originalString);
        System.out.println(newString);
    }

    public static void main1(String[] args) {
        String originalString = "hello, my name is henry";
        String newString = originalString.replace('h', 'H');

        System.out.println(originalString);
        System.out.println(newString);
    }
}
